home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / libraries / mui20dev.lha / MUI / Developer / C / Examples / Popup.c < prev    next >
C/C++ Source or Header  |  1994-02-11  |  5KB  |  187 lines

  1. #include "demo.h"
  2.  
  3.  
  4. SAVEDS ASM LONG StrObjFunc(REG(a2) Object *pop,REG(a1) Object *str)
  5. {
  6.     char *x,*s;
  7.     int i;
  8.  
  9.     get(str,MUIA_String_Contents,&s);
  10.  
  11.     for (i=0;;i++)
  12.     {
  13.         DoMethod(pop,MUIM_List_GetEntry,i,&x);
  14.         if (!x)
  15.         {
  16.             set(pop,MUIA_List_Active,MUIV_List_Active_Off);
  17.             break;
  18.         }
  19.         else if (!stricmp(x,s))
  20.         {
  21.             set(pop,MUIA_List_Active,i);
  22.             break;
  23.         }
  24.     }
  25.     return(TRUE);
  26. }
  27.  
  28.  
  29. SAVEDS ASM VOID ObjStrFunc(REG(a2) Object *pop,REG(a1) Object *str)
  30. {
  31.     char *x;
  32.     DoMethod(pop,MUIM_List_GetEntry,MUIV_List_GetEntry_Active,&x);
  33.     set(str,MUIA_String_Contents,x);
  34. }
  35.  
  36.  
  37. static const char *PopNames[] =
  38. {
  39.     "Stefan Becker",
  40.     "Martin Berndt",
  41.     "Georg Heßmann",
  42.     "Martin Horneffer",
  43.     "Martin Huttenloher",
  44.     "Kai Iske",
  45.     "Oliver Kilian",
  46.     "Franke Mariak",
  47.     "Klaus Melchior",
  48.     "Armin Sander",
  49.     "Matthias Scheler",
  50.     "Andreas Schildbach",
  51.     "Wolfgang Schildbach",
  52.     "Christian Scholz",
  53.     "Markus Stipp",
  54.     "Ibrahim Solmaz",
  55.     "Henri Veistera",
  56.     "Alber Weinert",
  57.     NULL
  58. };
  59.  
  60.  
  61. int main(int argc,char *argv[])
  62. {
  63.     static const struct Hook StrObjHook = { { NULL,NULL },(VOID *)StrObjFunc,NULL,NULL };
  64.     static const struct Hook ObjStrHook = { { NULL,NULL },(VOID *)ObjStrFunc,NULL,NULL };
  65.     APTR app,window,pop1,pop2,pop3,pop4,pop5,plist;
  66.     ULONG signals;
  67.     BOOL running = TRUE;
  68.  
  69.     init();
  70.  
  71.     app = ApplicationObject,
  72.         MUIA_Application_Title      , "Popup-Demo",
  73.         MUIA_Application_Version    , "$VER: Popup-Demo 7.28 (11.02.94)",
  74.         MUIA_Application_Copyright  , "©1993, Stefan Stuntz",
  75.         MUIA_Application_Author     , "Stefan Stuntz",
  76.         MUIA_Application_Description, "Demostrate popup objects.",
  77.         MUIA_Application_Base       , "POPUP",
  78.  
  79.         SubWindow, window = WindowObject,
  80.             MUIA_Window_Title, "Popup Objects",
  81.             MUIA_Window_ID   , MAKE_ID('P','O','P','P'),
  82.             WindowContents, VGroup,
  83.  
  84.                 Child, ColGroup(2),
  85.  
  86.                     Child, KeyLabel2("File:",'f'),
  87.                     Child, pop1 = PopaslObject,
  88.                         MUIA_Popstring_String, KeyString(0,256,'f'),
  89.                         MUIA_Popstring_Button, PopButton(MUII_PopFile),
  90.                         ASLFR_TitleText, "Please select a file...",
  91.                         End,
  92.  
  93.                     Child, KeyLabel2("Drawer:",'d'),
  94.                     Child, pop2 = PopaslObject,
  95.                         MUIA_Popstring_String, KeyString(0,256,'d'),
  96.                         MUIA_Popstring_Button, PopButton(MUII_PopDrawer),
  97.                         ASLFR_TitleText  , "Please select a drawer...",
  98.                         ASLFR_DrawersOnly, TRUE,
  99.                         End,
  100.  
  101.                     Child, KeyLabel2("Font:",'o'),
  102.                     Child, pop3 = PopaslObject,
  103.                         MUIA_Popstring_String, KeyString(0,80,'o'),
  104.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  105.                         MUIA_Popasl_Type , ASL_FontRequest,
  106.                         ASLFO_TitleText  , "Please select a font...",
  107.                         End,
  108.  
  109.                     Child, KeyLabel2("Fixed Font:",'i'),
  110.                     Child, pop4 = PopaslObject,
  111.                         MUIA_Popstring_String, KeyString(0,80,'i'),
  112.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  113.                         MUIA_Popasl_Type , ASL_FontRequest,
  114.                         ASLFO_TitleText  , "Please select a fixed font...",
  115.                         ASLFO_FixedWidthOnly, TRUE,
  116.                         End,
  117.  
  118.                     Child, KeyLabel2("Thanks To:",'n'),
  119.                     Child, pop5 = PopobjectObject,
  120.                         MUIA_Popstring_String, KeyString(0,60,'n'),
  121.                         MUIA_Popstring_Button, PopButton(MUII_PopUp),
  122.                         MUIA_Popobject_StrObjHook, &StrObjHook,
  123.                         MUIA_Popobject_ObjStrHook, &ObjStrHook,
  124.                         MUIA_Popobject_Object, plist = ListviewObject,
  125.                             MUIA_Listview_List, ListObject,
  126.                                 InputListFrame,
  127.                                 MUIA_List_SourceArray, PopNames,
  128.                                 End,
  129.                             End,
  130.                         End,
  131.                     End,
  132.                 End,
  133.             End,
  134.         End;
  135.  
  136.     if (!app)
  137.         fail(app,"Failed to create Application.");
  138.  
  139.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  140.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  141.  
  142.     DoMethod(window,MUIM_Window_SetCycleChain,pop1,pop2,pop3,pop4,pop5,NULL);
  143.  
  144.     /* A double click terminates the popping list with a successful return value. */
  145.     DoMethod(plist,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  146.         pop5,2,MUIM_Popstring_Close,TRUE);
  147.  
  148.  
  149. /*
  150. ** Input loop...
  151. */
  152.  
  153.     set(window,MUIA_Window_Open,TRUE);
  154.  
  155.     while (running)
  156.     {
  157.         switch (DoMethod(app,MUIM_Application_Input,&signals))
  158.         {
  159.             case MUIV_Application_ReturnID_Quit:
  160.             {
  161.              LONG active;
  162.  
  163.                 get(pop1,MUIA_Popasl_Active,&active);
  164.                 if (!active) get(pop2,MUIA_Popasl_Active,&active);
  165.                 if (!active) get(pop3,MUIA_Popasl_Active,&active);
  166.                 if (!active) get(pop4,MUIA_Popasl_Active,&active);
  167.  
  168.                 if (active)
  169.                     MUI_Request(app,window,0,NULL,"OK","Cannot quit now, still\nsome asl popups opened.");
  170.                 else
  171.                     running = FALSE;
  172.             }
  173.             break;
  174.         }
  175.  
  176.         if (running && signals) Wait(signals);
  177.     }
  178.  
  179.     set(window,MUIA_Window_Open,FALSE);
  180.  
  181. /*
  182. ** Shut down...
  183. */
  184.  
  185.     fail(app,NULL);
  186. }
  187.